package com.code2roc.jarmanage.util;

import com.code2roc.jarmanage.depoly.DepolyPlatform;
import com.code2roc.jarmanage.job.LogFileRollJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.concurrent.TimeUnit;

public class LogListenerUtil {
    private final static long interval = TimeUnit.SECONDS.toSeconds(5);

    public static void initLogListenter() throws Exception{
        if(!EnviromentUtil.getDepolyPlaform().equals(DepolyPlatform.Windows)){
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
            SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever();
            JobDetail jobDetail = JobBuilder.newJob(LogFileRollJob.class).withIdentity("logScanJob", "logScanGroup").storeDurably().build();
            Trigger trigger = TriggerBuilder.newTrigger().forJob(jobDetail).withIdentity("logScanJob", "logScanGroup").withSchedule(scheduleBuilder).build();
            scheduler.scheduleJob(jobDetail, trigger);
            if (!scheduler.isShutdown()) {
                scheduler.start();
            }
        }
    }
}
